From ca0382f09917aca88ff644de36eb82501d798004 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 18 Nov 2009 06:21:27 +0000 Subject: [PATCH] Fixed corruption of long UDP debug log messages by using socket_sendto() instead of fsockopen() with fwrite(). Using fwrite() causes the message to be split up into 8KB async send() calls, and whether they end up in the same UDP packet just depends on timing. --- RELEASE-NOTES | 2 ++ includes/GlobalFunctions.php | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 38acde8d8f..7ef10dbaba 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -638,6 +638,8 @@ Hopefully we will remove this configuration var soon) * (bug 21455) Fixed "Watch this page" checkbox appearing on some special pages even to non-logged in users * (bug 21551) Make Squid reponse limit configurable +* Fixed corruption of long UDP debug log messages by using socket_sendto() + instead of fsockopen() with fwrite(). == API changes in 1.16 == diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 85bbabb05d..1b6dc2a02c 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -411,13 +411,18 @@ function wfErrorLog( $text, $file ) { // IPv6 bracketed host $protocol = $m[1]; $host = $m[2]; - $port = $m[3]; + $port = intval( $m[3] ); $prefix = isset( $m[4] ) ? $m[4] : false; + $domain = AF_INET6; } elseif ( preg_match( '!^(tcp|udp):(?://)?([a-zA-Z0-9.-]+):(\d+)(?:/(.*))?$!', $file, $m ) ) { $protocol = $m[1]; $host = $m[2]; - $port = $m[3]; + if ( !IP::isIPv4( $host ) ) { + $host = gethostbyname( $host ); + } + $port = intval( $m[3] ); $prefix = isset( $m[4] ) ? $m[4] : false; + $domain = AF_INET; } else { throw new MWException( __METHOD__.": Invalid UDP specification" ); } @@ -429,12 +434,12 @@ function wfErrorLog( $text, $file ) { } } - $sock = fsockopen( "$protocol://$host", $port ); + $sock = socket_create( $domain, SOCK_DGRAM, SOL_UDP ); if ( !$sock ) { return; } - fwrite( $sock, $text ); - fclose( $sock ); + socket_sendto( $sock, $text, strlen( $text ), 0, $host, $port ); + socket_close( $sock ); } else { wfSuppressWarnings(); $exists = file_exists( $file ); -- 2.20.1